<template>
  <el-container>
    <el-header style="background-color:#59a6f5">
      <!-- 头部 -->
      <comm-header />
    </el-header>
    <!-- 标签导航栏组件 -->
    <tags-view class="tags"></tags-view>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="auto">
        <comm-aside />
      </el-aside>

      <!-- 主要 -->
      <el-main>
        <!-- 用if判断路由元信息内keepAlive是否为true如果是就缓存，如果缓存显示缓存的，如果不缓存就用不缓存的路由视图 -->
        <keep-alive v-if="$route.meta.keepAlive">
          <router-view></router-view>
        </keep-alive>
        <router-view v-else></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
//引入vuex中的state，不了解的参考vuex文档
import { mapState } from "vuex";
import CommAside from "@/components/CommAside.vue";
import CommHeader from "@/components/CommHeader.vue";
import TagsView from "../components/TagsView.vue";
export default {
  components: { CommAside, CommHeader, TagsView },
  data() {
    return {};
  },
  computed: {
    //引入vuex中state的变量，可以直接this.xxx调用到
    ...mapState(["isCollapse"])
  },
  watch: {
    //监听vuex中的变量如果变动了就赋值，从而改变菜单栏缩小展开
    isCollapse() {
      if (this.isCollapse) {
        this.subwidth = "64px";
      } else {
        this.subwidth = "200px";
      }
    }
  }
};
</script>

<style scoped>
.el-footer {
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-container {
  height: 100%;
}

.el-header,
.el-footer {
  background-color: #fff;
  color: #333;
  line-height: 60px;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.tags{
  padding-top: 3px;
}
</style>
